package io.renren.modules.sys.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.applicationUser.entity.UserEntity;
import io.renren.modules.sys.entity.SysUserInfoEntity;
import io.renren.modules.sys.service.SysUserInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("sysUserInfo/userInfo")
public class SysUserInfoController {
    @Autowired
    private SysUserInfoService sysUserInfoService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("applicationUser:user:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<SysUserInfoEntity> userList = sysUserInfoService.queryList(query);
        int total = sysUserInfoService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(userList, total, query.getLimit(), query.getCurrPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("applicationUser:user:info")
    public R info(@PathVariable("id") Long id){
        UserEntity user = sysUserInfoService.queryObject(id);

        return R.ok().put("user", user);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("applicationUser:user:delete")
    public R delete(@RequestBody Long[] ids){
        sysUserInfoService.deleteBatch(ids);

        return R.ok();
    }

}
